var path = require('path')
var fs = require('fs')
function GenerateDependPlugin(options) {
    // 使用 options 设置插件实例……
    this.options = options
}

GenerateDependPlugin.prototype.apply = function (compiler) {
    let reg = this.options.test,dst = this.options.dst;
    compiler.hooks.emit.tapAsync('GenerateDependPlugin', function (compilation, callback) {
        let depend = [];
        for (var filename in compilation.assets) {
            if (reg.test(filename)) {
                depend.push({
                    name: path.basename(filename),
                    path: filename
                })
            }
        }
        fs.writeFileSync(dst+'/depend.json', JSON.stringify(depend))
        callback();
    })
};

module.exports = GenerateDependPlugin;